﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.Remoting.Messaging;

namespace ServiceController
{
    public delegate DataAccess.DataAccessResult GetOperationStatusDelegate(String SubscriptionID, String CertificatePath, String ReqestID);
    
    public partial class ServiceController
    {
        GetOperationStatusDelegate _GetOperationStatusDelegate;
        public void GetOperationStatusAsync(String SubscriptionID, String CertificatePath, String ReqestID, object UserState)
        {
            _GetOperationStatusDelegate.BeginInvoke(SubscriptionID, CertificatePath, ReqestID,
                new AsyncCallback(GetOperationStatusCallback), UserState);
        }

        private void GetOperationStatusCallback(IAsyncResult ar)
        {
            AsyncResult aresult = (AsyncResult)ar;
            DataAccess.DataAccessResult result = _GetOperationStatusDelegate.EndInvoke(ar);
            OnGetOperationStatusComplete(new ServiceControllerEventArgs()
            {
                error = result.Error,
                UserState = ar.AsyncState,
                IsOperationSuccessful = result.IsOperationSuccessful,
                OperationStatus = result.OperationStatus,
            });
        }

        private DataAccess.DataAccessResult GetOperationStatus(String SubscriptionID, String CertificatePath, String ReqestID)
        {
            DataAccess.DataAccessResult result = da.GetOperationStatus(SubscriptionID, CertificatePath, ReqestID);
            return result;
        }
    }
}
